
const { $Toast } = require('../../dist/base/index');
Page({
  inputName(e) {
    this.data.actualname = e.detail.value;
    
  },
  onShareAppMessage() {
    return {
      title: '获取用户信息',
      path: 'page/pages/User'
    }
  },
  data: {
    hiddenmodalput: true,
    modalActions:[{
      name:"确定",
      color:'blank'
    }]
  },
  getUserInfo(info) {
    const userInfo = info.detail.userInfo

    this.setData({
      userInfo,
      hiddenmodalput: !this.data.hiddenmodalput
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },
  //真实姓名输入框内容修改事件
  nameInputChange({detail}){
    this.data.actualname = detail.detail.value;
  },
  //模态框确定按钮单击事件
  handleOk(){
    const userInfo = this.data.userInfo;

    var name = this.data.actualname;
    //判断是否为空
    if (!name || name.trim() == "") {
      wx.showModal({
        title: '提示',
        content: '请输入真实姓名',
        showCancel: false
      })
    }else{
      $Toast({
        content: '注册中',
        type: 'loading'
      });
      getApp().sendRequest({
        url:"api/user/addUser",
        data:{
          actualname: name,
          headpic: userInfo.avatarUrl
        },
        success:res => {
          if(res && res.data.code ===200){
            //跳转等待管理员审核
            getApp().goToResultInfo(1)
          }
        },
        fail:err => {
          $Toast({
            content: '注册错误',
            type: 'error'
          });
        },
        complete:() => {
          $Toast.hide();
        }
      })
    }
  }
  
})
